<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
      <!-- table -->
    <FormPanel ref="formPanel" :list="formList1" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false"  @formChange="formChangeHandle"/>
    <BaseDialog :visible.sync="visibleDrawer" :title="'VIN查询'" width="850px" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <VinVehicle @close="closeAdd" @save="save"></VinVehicle>
    </BaseDialog>
    <div style="padding-top: 1rem;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind(this)">保 存</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
    </Spin>
  </div>

</template>
<script>
  import { getListByPage, newSave, piliangqiyong, piliangtingyong, excelExport, editSave ,getCarList} from '@/api/claim/factory/SpeCarNonFirstPartTypeWarrantyMaintain';
  import {  getPartType,getPart } from '@/api/dictionary/index';
  import VinVehicle from '@/pages/claimDemage/tools/VinVehicle.vue';
  export default {
    components: {
      VinVehicle
    },
    data() {
      return {
        dataList1: [],
        visible: false,
        visibleDrawer: false,
        collapse: false,
        visibleAdd:false,
        infoId: null,
        flterValue: {}, //参数
        fetchParams: {}, //ipa 接口
        selectedRows: [], //选中经销商
        formList1: this.createFormList1(),
        saveData: null,
        activeName: '审核记录',
        modelName : '',
        loading: false,
      };
    },
    created() {
      this.chuqi();
    },
    methods: {

      async chuqi(){
        console.log("进来了")
        const res = await getPart();
        if (res.resultCode == 200) {
          this.formList1.find(x => x.fieldName == 'typeId').initialValue = '';
          this.formList1.find(x => x.fieldName == 'typeId').itemList = res.data.map(y => ({ text: y.name, value: y.code }));
        }

        const  res1 = await getPartType({ type: 5592 });
        if (res1.resultCode == 200) {
          this.formList1.find(x => x.fieldName == 'type').initialValue = '';
          this.formList1.find(x => x.fieldName == 'type').itemList = res1.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
        }
      },
      formChangeHandle(val) {
        console.log(val);
        this.saveData = val;
      },
      //搜索获取数据
      changeHandle(val) {
        this.fetchParams = val;
        console.log(val);
      },
      //保存
      chooseOrderNo() {
        this.visibleDrawer = true;
      },
      closeAdd() {
        this.visibleDrawer = false;
      },
      save(obj) {
        this.formList1.find(x => x.fieldName == 'vin').initialValue = obj[0].vin;
        this.formList1.find(x => x.fieldName == 'modelCode').initialValue = obj[0].modelCode;
        this.modelName = obj[0].modelName;
        this.visibleDrawer = false;
      },
      saveAdd() {
        this.visibleDrawer = false;
        this.visibleAdd = false;
        this.fetchParams = { ...this.fetchParams };
      },
      //新增保存
      async saveDialog() {
        this.$refs.formPanel.SUBMIT_FORM();
        if (this.saveData !== null) {
          this.loading = true;
          this.saveData.modelName = this.modelName;
          let res = await newSave(this.saveData);
          console.log(res);
          if (res.resultCode === 200) {
            this.$emit('save');
            return this.$notify.success({ title: '提示信息', message: '保存成功' });
          } else {
            this.loading = false;
            // this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
            // this.closeDialog();
          }
        }
      },
      //取消操作
      closeDialog() {
        this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
      },
      add() {},
      createFormList1() {
        return [
          {
            type: 'SELECT',
            label: '配件类型',
            fieldName: 'typeId',
            placeholder: '请选择配件类型...',
            itemList: [],
            filterable: true,
            rules: [{ required: true, message: '请选择配件类型...', trigger: 'change' }],
          },
          {
            type: 'INPUT',
            label: 'VIN',
            fieldName: 'vin',
            placeholder: '请选择vin...',
            rules: [{ required: true, message: '请选择vin...', trigger: 'change' }],
            initialValue: '',
            readonly: true ,// 只读
            unitRender: p => {
              return (
                <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.chooseOrderNo()} />
              </div>
            );
            }
          },
          {
            type: 'INPUT',
            label: '车型代码',
            fieldName: 'modelCode',
            disabled:true,
          },
          {
            type: 'SELECT',
            label: '类型',
            fieldName: 'type',
            itemList: [],
            placeholder: '请选择类型...',
            filterable: true,
            rules: [{ required: true, message: '请选择类型...', trigger: 'change' }],
            editRequired: true
          },
          {
            type: 'TEXT_AREA',
            label: '备注',
            fieldName: 'remarks',
            placeholder: '请输入备注...',
            rows: 2,
            selfCols: 1 // 元素占据几行
          }
        ];
      }
    }
  };
</script>

<style lang="less" scoped></style>
